﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Assets.Scripts.UserCache;
using ExitGames.Client.Photon;
using WorldOfSuperpowers_COMMON;
using WorldOfSuperpowers_COMMON.DataModel;

namespace Assets.Scripts.Handlers
{
    public class LoginHandler : BaseHandler
    {
        public override void Response(OperationResponse operationResponse)
        {
            string rezultStr = "";
            switch (operationResponse.ReturnCode)
            {
                case (byte)ReturnCode.Fail:
                    rezultStr = operationResponse.DebugMessage;
                    print(rezultStr);
                    TipsController._instance.ShowNewTipContent(rezultStr);
                    break;
                case (byte)ReturnCode.Success:
                    TipsController._instance.ShowNewTipContent("登录成功");
                    Dictionary<byte, object> content = operationResponse.Parameters;
                    object Vcontent = new object();
                    content.TryGetValue((byte) code,out Vcontent);
                    
                    UserDataModel model = ProtoTranslater.GetInstance().GetTypeFromBytes<UserDataModel>(Vcontent);
                    print("账号ID:"+model.UserID+",账号名称:"+model.UserName+",账号等级:"+model.UserLevel+"技能个数:"+model.SkillArr.Length);
                    UserInfos.CurrentUserModel = model;
                    LoginManager._instance.ActiveLoginPanel(false);
                    LoginManager._instance.ActiveLobbyPanel(true);
                    if (model.UserName != "")
                    {
                        print("该账号资料齐全，直接设置资料");
                        UserInfoManager._instance.SetUserInfo(model);
                    }
                    break;
            }
        }
    }
}
